﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Silverlight.Testing;
using System8ToyMC;
using System.Windows.Controls;

namespace t_System8ToyMCControls
{
    [TestClass]
    public class t_NamedValue : PresentationTest
    {
        NamedValue _val;

        [TestInitialize]
        public void CreateNVSetup()
        {
            _val = new NamedValue();
            TestPanel.Children.Add(_val);
        }

        [TestMethod]
        public void TestCtor()
        {
            Assert.IsNotNull(_val.ValueName, "Value name shouldn't be null");
            Assert.AreNotEqual("", _val.ValueName, "Expected value name to be real");
        }

        [TestMethod]
        public void TestNameSetting()
        {
            _val.ValueName = "Jet b:";
            TextBlock b = _val.FindName("TBValueName") as TextBlock;
            Assert.IsNotNull(b, "Expecting the text block to be called Valuename");
            Assert.AreEqual("Jet b:", b.Text, "Text block didn't have its value set correctly");
        }

        [TestMethod]
        public void TestValueSetting()
        {
            _val.Value = 55.6;
            TextBox b = _val.FindName("TBValue") as TextBox;
            Assert.IsNotNull("Expecting the text box to be called TBValue!");
            Assert.AreEqual("55.6", b.Text, "It doesn't look like the value was propagated!");

            b.Text = "94.1";
            Assert.AreEqual(94.1, _val.Value, "The value didn't change when the textbox was updated!");
        }

        [TestMethod]
        public void TestROSetFalse()
        {
            Assert.IsFalse(_val.ReadOnly, "Expected inital setting to be false for r/o!");
            TextBlock roB = _val.FindName("TBROValue") as TextBlock;
            TextBox B = _val.FindName("TBValue") as TextBox;
            Assert.IsNotNull(B, "could not find the text box!");
            Assert.IsNotNull(roB, "Could not find the ro value!");
            Assert.AreEqual(System.Windows.Visibility.Collapsed, roB.Visibility, "Visibility of the invisible guy is... well, not visible!");
            Assert.AreEqual(System.Windows.Visibility.Visible, B.Visibility, "Visibility of textbox is not set visible!");

            _val.ReadOnly = true;
            Assert.AreEqual(System.Windows.Visibility.Visible, roB.Visibility, "Visibility of the invisible guy is... well, still not visible!");
            Assert.AreEqual(System.Windows.Visibility.Collapsed, B.Visibility, "Visibility of textbox is not set collapsed!");
        }

        [TestMethod]
        public void TestROValue()
        {
            _val.ReadOnly = true;
            _val.Value = 55.6;
            TextBlock roB = _val.FindName("TBROValue") as TextBlock;
            Assert.AreEqual("55.6", roB.Text, "The TextBlock didn't get the proper binding!");
        }

        [TestMethod]
        public void TestName()
        {
            _val.Path = "n/TotalValue";
            Assert.AreEqual("n/TotalValue", _val.Path, "Value incorrect");
        }
    }
}
